package com.my.characters;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @description:
 * @author: marshal
 * @date: 2021-08-24 10:41 AM
 *
 * All character stream classes are descended from Reader and Writer. As with byte streams, there are character stream classes that specialize in file I/O: FileReader and FileWriter.
 *
 * reference : https://docs.oracle.com/javase/tutorial/essential/io/charstreams.html
 */
public class CopyCharacters {
    public static void main(String[] args) throws IOException {

        FileReader fr = null;
        FileWriter fw = null;

        try {
            fr = new FileReader("file/xanadu.txt");
            fw = new FileWriter("file/characteroutput.txt");

            int c;
            while ((c = fr.read()) != -1) {
                fw.write(c);
            }
        } finally {
            if (fr != null) {
                fr.close();
            }
            if (fw != null) {
                fw.close();
            }
        }
    }
}
